package com.example.file;

import java.io.*;

public class FileTest2 {
    public static void main(String[] args) {
        String source = "C:\\Program Files\\Git\\project\\demo\\src\\main\\resources\\die.txt";
        print(source);
    }

    public static void print(String source) {
        int charCount = 20;
        try (BufferedReader reader = new BufferedReader(new FileReader(source))) {
            String line;
            while ((line = reader.readLine()) != null) {
                printString();
                int maxIndex = line.length() / charCount + ((line.length() % charCount) > 0 ? 1 : 0);
                for (int i = 0; i < maxIndex; i++) {
                    printString();
                    System.out.println(line.substring(i * charCount,  ((i == maxIndex -1) ? line.length() : i * charCount + charCount )));
                    printString();
                }
                printString();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void printString() {
        System.out.println("2024-11-05 14:29:57.345 INFO  [com.alibaba.nacos.common.remote.client] - [af767583-dc18-4a21-8968-16dfe1b0a657] Receive server push request, request = NotifySubscriberRequest, requestId = 217348\n" +
                "2024-11-05 14:29:57.347 INFO  [com.alibaba.nacos.common.remote.client] - [af767583-dc18-4a21-8968-16dfe1b0a657] Ack server push request, request = NotifySubscriberRequest, requestId = 217348");
    }
}
